package com.heima.service.impl;

import com.heima.model.article.dtos.SearchWords;
import com.heima.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author itheima
 * @since 2023-01-10
 */
@Service
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<SearchWords> getHistoryList() {

        // 1. 调用mongo查询方法
        Query query = new Query();
        query.addCriteria(Criteria.where("userId").is("4"));
        query.limit(5);

        // 2. 查询条件是我的 userId = 我

        return mongoTemplate.find(query, SearchWords.class);
    }
}
